<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const counter = ref(5)

// 倒计时返回到首页
onMounted(() => {
  const timer = setInterval(() => {
    counter.value--
    if (counter.value <= 0) {
      clearInterval(timer)
      router.push('/')
    }
  }, 1000)
  
  // 组件销毁时清除定时器
  return () => clearInterval(timer)
})

// 立即返回首页
const goHome = () => {
  router.push('/')
}

// 随机生成皮影戏图案背景
const patterns = [
  '🎭', '🎨', '🎪', '🎭', '🎨', '🎪',
  '🎭', '🎨', '🎪', '🎭', '🎨', '🎪',
  '🎭', '🎨', '🎪', '🎭', '🎨', '🎪'
]

// 随机打乱图案顺序
const shuffledPatterns = [...patterns].sort(() => Math.random() - 0.5)
</script>

<template>
  <div class="not-found-container">
    <!-- 背景图案 -->
    <div class="pattern-background">
      <span v-for="(pattern, index) in shuffledPatterns" :key="index" class="background-pattern">
        {{ pattern }}
      </span>
    </div>
    
    <!-- 主内容 -->
    <div class="not-found-content">
      <div class="not-found-icon">🎭</div>
      <h1 class="not-found-title">页面未找到</h1>
      <p class="not-found-message">
        您访问的页面不存在或已被移除。
        <br>
        <span class="countdown-message">
          您将在 <strong>{{ counter }}</strong> 秒后自动返回首页
        </span>
      </p>
      <div class="shadow-puppet-animation">
        <div class="shadow-puppet shadow-puppet-1"></div>
        <div class="shadow-puppet shadow-puppet-2"></div>
      </div>
      <button @click="goHome" class="home-button">
        返回首页
      </button>
    </div>
  </div>
</template>

<style scoped>
.not-found-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background-color: var(--color-background);
  overflow: hidden;
}

/* 背景图案 */
.pattern-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  grid-template-rows: repeat(auto-fill, minmax(80px, 1fr));
  opacity: 0.05;
  z-index: 0;
}

.background-pattern {
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 主内容 */
.not-found-content {
  text-align: center;
  padding: 3rem;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  max-width: 500px;
  width: 90%;
  position: relative;
  z-index: 1;
}

.not-found-icon {
  font-size: 5rem;
  margin-bottom: 1.5rem;
}

.not-found-title {
  font-size: 2.5rem;
  color: var(--color-primary);
  margin-bottom: 1rem;
  font-family: 'STZhongsong', serif;
}

.not-found-message {
  font-size: 1.1rem;
  color: var(--color-text-light);
  line-height: 1.6;
  margin-bottom: 2rem;
}

.countdown-message {
  display: block;
  margin-top: 1rem;
  font-size: 1rem;
  color: var(--color-text);
}

.countdown-message strong {
  color: var(--color-primary);
  font-size: 1.2rem;
}

/* 皮影动画 */
.shadow-puppet-animation {
  position: relative;
  height: 120px;
  margin: 2rem 0;
  overflow: hidden;
}

.shadow-puppet {
  position: absolute;
  width: 80px;
  height: 120px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.8;
  animation: puppetMove 6s infinite alternate ease-in-out;
}

.shadow-puppet-1 {
  left: 0;
  background-image: url('https://picsum.photos/id/119/100/150');
  animation-delay: 0s;
  transform: scaleX(-1); /* 镜像翻转 */
}

.shadow-puppet-2 {
  right: 0;
  background-image: url('https://picsum.photos/id/129/100/150');
  animation-delay: 1s;
}

@keyframes puppetMove {
  0% {
    transform: translateY(0) scaleX(1);
  }
  25% {
    transform: translateY(-10px) scaleX(1);
  }
  50% {
    transform: translateY(0) scaleX(1.05);
  }
  75% {
    transform: translateY(10px) scaleX(1);
  }
  100% {
    transform: translateY(0) scaleX(1);
  }
}

/* 特殊样式处理第二个皮影，保持镜像 */
.shadow-puppet-2 {
  animation-name: puppetMove2;
}

@keyframes puppetMove2 {
  0% {
    transform: translateY(0) scaleX(-1);
  }
  25% {
    transform: translateY(-10px) scaleX(-1);
  }
  50% {
    transform: translateY(0) scaleX(-1.05);
  }
  75% {
    transform: translateY(10px) scaleX(-1);
  }
  100% {
    transform: translateY(0) scaleX(-1);
  }
}

/* 返回首页按钮 */
.home-button {
  background-color: var(--color-primary);
  color: white;
  border: none;
  padding: 0.8rem 2rem;
  font-size: 1.1rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease;
}

.home-button:hover {
  background-color: var(--color-secondary);
  transform: translateY(-2px);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .not-found-content {
    padding: 2rem;
  }
  
  .not-found-icon {
    font-size: 4rem;
  }
  
  .not-found-title {
    font-size: 2rem;
  }
  
  .shadow-puppet {
    width: 60px;
    height: 90px;
  }
}

@media (max-width: 480px) {
  .not-found-content {
    padding: 1.5rem;
  }
  
  .not-found-icon {
    font-size: 3rem;
  }
  
  .not-found-title {
    font-size: 1.8rem;
  }
  
  .shadow-puppet {
    width: 50px;
    height: 75px;
  }
  
  .home-button {
    width: 100%;
  }
}
</style>